package homework.day03;

import java.io.*;

public class Test2 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //获取当前目录下的所有子项
        File dir = new File(".");
        //获取dir中所有名字末尾为”.obj“的文件
        File[] subs = dir.listFiles(f->f.getName().endsWith(".obj"));
        //遍历所有文件
        for(int i=0;i<subs.length;i++){
            //取得下标为i的文件
            File sub = subs[i];
            //字节输入流读取文件
            FileInputStream fis = new FileInputStream(sub);
            //对象输入流连接到字节流上
            ObjectInputStream ois = new ObjectInputStream(fis);
            //反序列化操作
            Object obj = ois.readObject();
            //判断是否可以强转
            if(obj instanceof User){
                User user = (User)obj;
                System.out.println(user);
            }

        }



    }
}
